package com.example.myapplication

import android.graphics.Color
import android.os.Bundle
import android.view.Gravity
import android.view.ViewGroup
import android.widget.Button
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity


class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
//        setContentView(R.layout.activity_main)
//        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
//            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
//            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
//            insets
//        }
//        val textView: TextView = findViewById(R.id.textView)
//        val myButton: Button = findViewById(R.id.button)
//
//        myButton.setOnClickListener {
//            textView.text = getString(R.string.clicked)
//        }

        val linearLayout= LinearLayout(this)
        linearLayout.orientation=LinearLayout.VERTICAL
        linearLayout.setBackgroundColor(Color.WHITE)

        //图片
        val imageView = ImageView(this)
        imageView.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
        imageView.adjustViewBounds = true
        imageView.setImageResource(R.drawable.flag)
        linearLayout.addView(imageView)

        //文本（hello world）设计
        val textView=TextView(this)
        textView.layoutParams=ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT)
        textView.textSize=20F
        textView.gravity = Gravity.CENTER
        textView.text=getString(R.string.text_view)
        linearLayout.addView(textView)

        //按钮
        val button=Button(this)
        button.width= ViewGroup.LayoutParams.MATCH_PARENT
        button.height=ViewGroup.LayoutParams.WRAP_CONTENT
        button.text=getString(R.string.button);
        linearLayout.addView(button)

        setContentView(linearLayout)

        button.setOnClickListener {

            button.text = getString(R.string.clicked)
        }
    }

}